import pandas as pd


# 由交易信号产生实际持仓
def position_for_OKEx_future(df, signal_name):

    if signal_name == 'signal_simple_bolling':
        df['signal_'] = df['signal']
        # 在产生signal的k线结束的时候，进行买入
        df['signal_'].fillna(method='ffill', inplace=True)
        df['signal_'].fillna(value=0, inplace=True)  # 将初始行数的signal补全为0
        df['pos'] = df['signal_'].shift()
        df['pos'].fillna(value=0, inplace=True)  # 将初始行数的pos补全为0

    elif signal_name == 'signal_reverse_trade':
        df['signal_'] = df['signal']
        # 在产生signal的k线结束的时候，进行买入
        df['signal_'].fillna(method='ffill', inplace=True)
        df['signal_'].fillna(value=0, inplace=True)  # 将初始行数的signal补全为0
        df['pos'] = df['signal_'].shift()
        df['pos'].fillna(value=0, inplace=True)  # 将初始行数的pos补全为0

        df['signal_reverse_'] = df['signal_reverse']
        # 在产生signal的k线结束的时候，进行买入
        df['signal_reverse_'].fillna(method='ffill', inplace=True)
        df['signal_reverse_'].fillna(value=0, inplace=True)  # 将初始行数的signal补全为0
        df['pos_reverse'] = df['signal_reverse_'].shift()
        df['pos_reverse'].fillna(value=0, inplace=True)  # 将初始行数的pos补全为0
    return df
